package com.jvtd.baseProject.ui.guide;

import android.content.Context;
import android.content.Intent;
import android.view.View;


import com.jvtd.baseProject.R;
import com.jvtd.baseProject.base.BaseMvpActivity;
import com.jvtd.baseProject.ui.main.MainActivity;
import com.jvtd.widget.viewPager.JvtdViewPager;
import com.jvtd.widget.viewPager.pagerAdapter.JvtdPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

public class GuideActivity extends BaseMvpActivity implements GuideMvpView, View.OnClickListener
{
  @BindView(R.id.guide_page_view)
  JvtdViewPager mViewPager;

  @Inject
  GuidePresenter<GuideMvpView> mPresenter;

  private List<View> viewList;

  public static Intent getIntent(Context context)
  {
    return new Intent(context, GuideActivity.class);
  }

  @Override
  protected void initInject()
  {
    getActivityComponent().inject(this);
  }

  @Override
  protected void getLayout()
  {
    setContentView(R.layout.activity_guide);
  }

  @Override
  protected void initViewAndData()
  {
    mPresenter.onAttach(this);

    initViews();
    initAdapter();
  }


  private void initViews()
  {
    viewList = new ArrayList<>();
    View page_1 = View.inflate(this, R.layout.fragment_guide_1, null);
    View page_2 = View.inflate(this, R.layout.fragment_guide_2, null);
    View page_3 = View.inflate(this, R.layout.fragment_guide_3, null);
    page_3.findViewById(R.id.start_view).setOnClickListener(this);
    viewList.add(page_1);
    viewList.add(page_2);
    viewList.add(page_3);
  }

  private void initAdapter()
  {
    JvtdPagerAdapter adapter = new JvtdPagerAdapter(viewList);
    mViewPager.setOffscreenPageLimit(3);
    mViewPager.setAdapter(adapter);
  }

  @Override
  public void onClick(View v)
  {
    //进入登录界面
    mPresenter.toActivity();
  }

  @Override
  public void openActivity()
  {
    Intent intent = MainActivity.getIntent(GuideActivity.this);
    startActivity(intent);
    finish();
  }

  @Override
  protected void onDestroy()
  {
    mPresenter.onDetach();
    super.onDestroy();
  }
}
